<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        1234哈哈哈哈哈哈哈哈哈，mmhhhrgertgr，他认为太过温柔,rfwerfw子啊和ui收费后
    </div>
    <script>
        function truncateText(element, maxLength) {
            const text = element.textContent;
            if (text.length > maxLength) {
                element.textContent = text.substring(0, maxLength) + '...';
            }
        } 
        const div = document.getElementById('app')
        truncateText(div, 40);
    </script>
</body>
<style>
    #app {
        width: 200px;
        border: 1px solid red;
    }
</style>
</html>